<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no,minimal-ui">
        <title>菩提阁</title>
        <link rel="icon" href="./../images/favico.ico">
        <!--不同屏幕尺寸根字体设置-->
        <script src="./../js/base.js"></script>
        <script src="./../js/jquery.min.js"></script>
        <script src="./../js/qrcode.min.js"></script>
        <!--element-ui的样式-->
        <link rel="stylesheet" href="../../backend/plugins/element-ui/index.css" />
        <!-- 引入样式  -->
        <link rel="stylesheet" href="../styles/index.css" />
        <!--本页面内容的样式-->
        <link rel="stylesheet" href="./../styles/pay-success.css" />
    </head>
    <body>
        <div id="pay_success" class="app">
            <div class="divHead">
                <div class="divTitle">
                    <i class="el-icon-arrow-left" @click="goBack"></i>
                    菩提阁
                    <img src="./../images/home.png" @click="toMainPage"/>
                </div>
            </div>
            <div class="divContent">

                <div class="divDesc">订单号 {{oid}}</div>
                <div class="divDesc">待支付 {{amount}}</div>
                <div id="payqrcode" ref="qrCodeDiv"></div>
                <div class="divDesc">请使用微信支付</div>


            </div>
        </div>
        <!-- 开发环境版本，包含了有帮助的命令行警告 -->
        <script src="../../backend/plugins/vue/vue.js"></script>
        <!-- 引入组件库 -->
        <script src="../../backend/plugins/element-ui/index.js"></script>
        <!-- 引入axios -->
        <script src="../../backend/plugins/axios/axios.min.js"></script>
        <script src="./../js/common.js"></script>
        <script src="./../js/request.js"></script>
        <script>

        new Vue({
            el:"#pay_success",
            data(){
                return {
                    finishTime:'',
                    oid:'',
                    amount:'',
                    payUrl:'',
                    timer:''

                }
            },
            computed:{},
            created(){
                this.initData();

                axios.get("/pay/getPayURL?oid="+this.oid+"&amount="+this.amount).then(res =>{
                    let result = res.data;
                    if (result.code == 1){
                        new QRCode("payqrcode",{
                            text: result.data
                        })
                    }
                })
                this.timer =  setInterval(()=>{
                    console.log("查询用户是否已支付")
                    axios.get("/order/findOrderStatus?oid="+this.oid).then(resp =>{
                        let result = resp.data
                        if (result.code == 1){
                            //支付成功
                            window.requestAnimationFrame(()=>{
                                window.location.href = '/front/page/pay-success.html'
                            })
                        }
                    })
                },5000);

                setTimeout(()=>{
                    clearInterval(this.timer)
                    console.log("50秒已经过，查询用户是否未支付")
                    axios.get("/order/findOrderStatus?oid="+this.oid).then(resp =>{
                        let result = resp.data
                        if (result.code == 0){
                            //支付超时
                            window.requestAnimationFrame(()=>{
                                window.location.href = '/front/page/pay-failed.html'
                            })
                        }
                    })
                },50000);

            },
            mounted(){

            },
            methods:{

                goBack(){
                    window.requestAnimationFrame(()=>{
                        window.location.replace('/front/index.html')
                    })   
                },
                async initData(){
                    const params = parseUrl(window.location.search)
                    this.oid = params.oid
                    this.amount = params.amount
                    // this.payUrl = params.payUrl
                    // window.payUrl = this.payUrl;
                },
                toOrderPage(){
                    window.requestAnimationFrame(()=>{
                        window.location.replace('/front/page/order.html')
                    })  
                },
                toMainPage(){
                    window.requestAnimationFrame(()=>{
                        window.location.replace('/front/index.html')
                    })  
                }
                
            }
        })
        // new QRCode("payqrcode",{
        //     text: sessionStorage.getItem("payUrl")
        // })
        // setInterval(function () {
        //     axios.get("/order/findOrderStatus?id=")
        // })
        </script>
    </body>
</html>